// main.go

package main

import (

	_ "github.com/go-sql-driver/mysql"
	"github.com/gin-gonic/gin"
	"log"
	"./models"
)

var router *gin.Engine

func main() {
	// Set Gin to production mode
	gin.SetMode(gin.ReleaseMode)

	defer models.DBO.Close()
	// Set the router as the default one provided by Gin
	router = gin.Default()
	
	// Process the templates at the start so that they don't have to be loaded
	// from the disk again. This makes serving HTML pages very fast.
	router.LoadHTMLGlob("templates/*")

	// Initialize the routes
	initializeRoutes()

	// Start serving the application
	log.Println("start listening...")
	router.Run(":3000")
}

// Render one of HTML, JSON or CSV based on the 'Accept' header of the request
// If the header doesn't specify this, HTML is rendered, provided that
// the template name is present


